package org.electrical.controller.functionality;

import org.electrical.dao.ElePlanDao;
import org.electrical.pojo.ElePlan;
import org.electrical.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/plan")
@CrossOrigin(value = "*")
public class ElePlanController {

    @Autowired
    ElePlanDao elePlanDao;

    @RequestMapping("/getBySaleId")
    @ResponseBody
    public ResponseResult<List<ElePlan>> getBySaleId(int saleId) throws Exception {

        List<ElePlan> list = elePlanDao.getBySaleId(saleId);
        return new ResponseResult(list);

    }

    @RequestMapping("/add")
    @ResponseBody
    public ResponseResult add(ElePlan elePlan) throws Exception {

        elePlanDao.add(elePlan);
        return ResponseResult.createSuccessResult();

    }

    @RequestMapping("/delete")
    @ResponseBody
    public ResponseResult delete(int planId) throws Exception {

        elePlanDao.delete(planId);
        return ResponseResult.createSuccessResult();

    }

    @RequestMapping("/update")
    @ResponseBody
    public ResponseResult update(ElePlan elePlan) throws Exception {

        elePlanDao.update(elePlan);
        return ResponseResult.createSuccessResult();

    }

    @RequestMapping("/addEffect")
    @ResponseBody
    public ResponseResult addEffect(ElePlan elePlan) throws Exception {

        elePlanDao.addEffect(elePlan);
        return ResponseResult.createSuccessResult();

    }

}
